package ch.idsia.ai.agents.controllers.myai.tests;

import ch.idsia.ai.agents.controllers.myai.Ratio;
import org.junit.*;

import static org.junit.Assert.*;

/**
 * Created by IntelliJ IDEA.
 * User: Blake
 * Date: Jul 1, 2010
 * Time: 6:24:06 PM
 * To change this template use File | Settings | File Templates.
 */
public class RatioTest
{
    @Test   public void testRatio()
    {
        for(int i = 0; i < 100; ++i)
        {
            int num = (int) Math.floor(Math.random()*100)+1;
            int den = (int) Math.floor(Math.random()*100)+1;
            Ratio ratio = new Ratio(num, den);
            assertNotNull("testRatio", ratio);
            assertTrue("testRatio", ratio.getNumerator() == num);
            assertTrue("testRatio", ratio.getDenominator() == den);
        }
    }
    
    @Test   public void testGetRatio()
    {
        Ratio ratio = new Ratio(1,2);
        double value = 0.5;
        assertTrue(ratio.getRatio() == value);

        ratio = new Ratio(3,4);
        value = .75;
        assertTrue(ratio.getRatio() == value);

        ratio = new Ratio(1,10);
        value = 0.1;
        assertTrue(ratio.getRatio() == value);

        ratio = new Ratio(4,8);
        value = 0.5;
        assertTrue(ratio.getRatio() == value);
    }

    @Test   public void testGetNumerator()
    {
        for (int i = 0; i < 25; ++i)
        {
            int value = (int)(Math.random()*100)+1;
            Ratio ratio = new Ratio(value, 0);
            assertTrue(value == ratio.getNumerator());
        }
    }

    @Test   public void testGetDenominator()
    {
        for (int i = 0; i < 25; ++i)
        {
            int value = (int)(Math.random()*100)+1;
            Ratio ratio = new Ratio(0, value);
            assertTrue(value == ratio.getDenominator());
        }
    }

    @Test public void testIncrementTries()
    {
        int start = (int)(Math.random()*100)+1;
        Ratio ratio = new Ratio(0, start);
        for (int i = 0; i < 25; ++i)
        {
            assertTrue(ratio.getDenominator() == start+i);
            ratio.incrementTries();
        }
    }

    @Test   public void testSuccess()
    {

    }
}
